﻿using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Text;

namespace LIU.Framework.Core.Inject
{
    /// <summary>
    /// 拦截器
    /// </summary>
    public class BaseIntercept : IInterceptor
    {

        /// <summary>
        /// 拦截方法
        /// </summary>
        /// <param name="invocation"></param>
        public void Intercept(IInvocation invocation)
        {
            PreProceed(invocation);
            DoProceed(invocation);
            PostProceed(invocation);
        }


        /// <summary>
        /// 执行目标方法
        /// </summary>
        /// <param name="invocation"></param>
        protected virtual void DoProceed(IInvocation invocation)
        {
            //执行目标方法
            invocation.Proceed();
        }

        /// <summary>
        /// 在执行目标方法前执行的前置方法
        /// </summary>
        /// <param name="invocation"></param>
        protected virtual void PreProceed(IInvocation invocation)
        {
        }
        /// <summary>
        /// 在成功执行方法后执行的后置方法
        /// </summary>
        /// <param name="invocation"></param>
        protected virtual void PostProceed(IInvocation invocation)
        {
            //if (invocation.ReturnValue is string)
            //    invocation.ReturnValue = invocation.ReturnValue + "123";
        }
    }
}
